# shared/Makefile for libelf.
# Copyright (C) 1995 Michael Riepe <riepe@ifwsn4.ifw.uni-hannover.de>
# 
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
# 
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Library General Public License for more details.
# 
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

prefix = @prefix@
exec_prefix = @exec_prefix@
libdir = $(exec_prefix)/lib

CC = @CC@
MV = mv -f
RM = rm -f
LN_S = @LN_S@
INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@

CFLAGS = @CFLAGS@
CPPFLAGS = @CPPFLAGS@
DEFS = -DHAVE_CONFIG_H
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@

COMPILE = $(CC) -c -fPIC $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) $(XCFLAGS)

# no user serviceable parts below

PACKAGE = @PACKAGE@
VERSION = @VERSION@
MAJOR = @MAJOR@

SHELL = /bin/sh
@SET_MAKE@

srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@

topdir = ..
subdir = shared

.SUFFIXES:
.SUFFIXES: .c .o
.c.o:
	@$(RM) $@
	$(COMPILE) $<

INCLUDES = -I$(topdir) -I$(srcdir)/..

# generic sources
SRCS1 = begin.c cntl.c end.c errmsg.c errno.c fill.c flag.c getarhdr.c \
	getarsym.c getbase.c getdata.c getident.c getscn.c hash.c kind.c \
	ndxscn.c newdata.c newscn.c next.c nextscn.c rand.c rawdata.c \
	rawfile.c strptr.c update.c version.c
OBJS1 = begin.o cntl.o end.o errmsg.o errno.o fill.o flag.o getarhdr.o \
	getarsym.o getbase.o getdata.o getident.o getscn.o hash.o kind.o \
	ndxscn.o newdata.o newscn.o next.o nextscn.o rand.o rawdata.o \
	rawfile.o strptr.o update.o version.o

# 32-bit sources
SRCS2 = 32.fsize.c 32.getehdr.c 32.getphdr.c 32.getshdr.c 32.newehdr.c \
	32.newphdr.c 32.xlatetof.c
OBJS2 = 32.fsize.o 32.getehdr.o 32.getphdr.o 32.getshdr.o 32.newehdr.o \
	32.newphdr.o 32.xlatetof.o

# support
SRCS3 = cook.c data.c input.c
OBJS3 = cook.o data.o input.o

# nlist
SRCS4 = nlist.c
OBJS4 = nlist.o

SRCS = $(SRCS1) $(SRCS2) $(SRCS3) $(SRCS4)
OBJS = $(OBJS1) $(OBJS2) $(OBJS3) $(OBJS4)

# missing functions
LIBSRCS = memset.c
LIBOBJS = @LIBOBJS@

DISTFILES = Makefile.in

all: message shared

message:
	@echo "    ----------------------------------------"
	@echo "    In its current form, the \"shared\" target"
	@echo "    will only work on Linux/ELF systems."
	@echo "    If you can get it to work on another"
	@echo "    system, please let me know how.    -- MR"
	@echo "    ----------------------------------------"
	@test "`uname`" = Linux
	@sleep 2

shared: libelf.so.$(MAJOR)

libelf.so.$(MAJOR): $(OBJS) $(LIBOBJS)
	@$(RM) $@ libelf.so.$(VERSION) libelf.so
	$(CC) -shared -Wl,-soname,$@ $(LDFLAGS) $(OBJS) $(LIBOBJS) $(LIBS) -o $@
	$(MV) $@ libelf.so.$(VERSION)
	$(LN_S) libelf.so.$(VERSION) $@
	$(LN_S) $@ libelf.so

$(SRCS) $(LIBSRCS):
	@$(LN_S) $(topdir)/$@ $@

install: shared
	$(INSTALL_PROGRAM) libelf.so.$(VERSION) $(libdir)
	$(RM) $(libdir)/libelf.so $(libdir)/libelf.so.$(MAJOR)
	cd $(libdir) && $(LN_S) libelf.so.$(VERSION) libelf.so.$(MAJOR)
	cd $(libdir) && $(LN_S) libelf.so.$(VERSION) libelf.so

uninstall:
	cd $(libdir) && $(RM) libelf.so libelf.so.$(MAJOR) libelf.so.$(VERSION)

mostlyclean:
	$(RM) *~ core a.out errlist Log

clean: mostlyclean
	$(RM) *.[oa] *.so* $(SRCS) $(LIBSRCS)

distclean: clean
	$(RM) Makefile

maintainer-clean: distclean

distdir = $(topdir)/$(PACKAGE)-$(VERSION)/$(subdir)
dist: $(DISTFILES)
	for file in $(DISTFILES); do \
	  ln $(srcdir)/$$file $(distdir) || \
	    cp -p $(srcdir)/$$file $(distdir) || exit 1; \
	done

# For the justification of the following Makefile rules, see node
# `Automatic Remaking' in GNU Autoconf documentation.

Makefile: Makefile.in $(topdir)/config.status
	cd $(topdir) && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= ./config.status

# Tell versions [3.59,3.63) of GNU make not to export all variables.
# Otherwise a system limit (for SysV at least) may be exceeded.
.NOEXPORT:
